<template>
  <div>
    <van-nav-bar title="设置密码" right-text="跳过" @click-right="next" />
    <van-form validate-first @submit="setPassword" @failed="onFailed">
      <!-- 通过 pattern 进行正则校验 -->
      <van-field
        v-model="password"
        name="pattern"
        placeholder="请输入密码"
        :rules="[{ pattern, message: '请输入正确内容' }]"
      />
      <!-- 通过 validator 进行函数校验 -->
      <van-field
        v-model="passwordChecked"
        name="validator"
        placeholder="请再次输入密码"
        :rules="[{ pattern, message: '请输入正确内容' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { zzhReset } from "../util/http.js";
export default {
  // 组件名称
  name: "demo", // 组件参数 接收来自父组件的数据
  props: [],
  components: {},
  data() {
    return {
      password: "",
      passwordChecked: "",
      pattern: /\d{6}/
    };
  },
  computed: {},
  watch: {},
  methods: {
    next() {
        this.$router.push('/set-message')
    },
    onFailed(errorInfo) {
      console.log("failed", errorInfo);
    },
    async setPassword() {
      if (this.password == this.passwordChecked) {
        const info = this.$store.sdate.info;
        info.password = this.password;
        console.log(info);
        const res = await zzhReset(info);
        console.log(res);
      } else {
        this.$toast.fail("两次密码不正确");
      }
    }
  },
  beforeCreate() {},
  created() {},
  beforeMount() {},
  mounted() {}
};
</script> 
<style scoped>
</style>
